<template>
	<view>
		<u-navbar title="个人资料" :autoBack="true" :placeholder="true"></u-navbar>
		<view class="picture">
			<ImgUpload :maxCount="1" :playback="arr" @callback="callback1" />
		</view>
		<view class="from">
			<view class="name item">
				<text style="color: rgba(0, 0, 0, 0.4);">呢称</text>
				<input type="nickname" placeholder="请输入昵称" v-model="userinfo.nickname" />
			</view>
			<view class="signature item">
				<text style="color: rgba(0, 0, 0, 0.4);">个性签名</text>
				<input type="text" placeholder="个性签名" v-model="userinfo.bio">
			</view>
		</view>
		<view class="btn" @click="btnClick">
			保存
		</view>
	</view>
</template>

<script>
	import ImgUpload from '@/components/ImgUpload/ImgUpload.vue'
	export default {
		data() {
			return {
				userinfo: {
					nickname: "",
					avatar: "",
					bio: ""
				},
				arr: [{
					url: "",
				}]
			};
		},
		components: {
			ImgUpload
		},
		onLoad() {
			this.getuserinfo()
		},
		methods: {
			//获取用户头像
			callback1(e) {
				this.userinfo.avatar = e[0].url
				console.log(e);
			},
			// 保存
			async btnClick() {
				let {
					code,
					msg
				} = await this.$api.profile(this.userinfo)
				// console.log(res);
				this.$u.toast(msg)
				if (code === 1) {
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			},
			// 获取个人信息
			async getuserinfo() {
				let res = await this.$api.getuserinfo()
				this.userinfo = res.data
				this.arr[0].url = res.data.avatar
				// console.log(res);
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.picture {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 480rpx;

	}

	.from {
		box-sizing: border-box;
		padding: 0 32rpx;
		color: rgba(0, 0, 0, 0.8);
		font-size: 28rpx;
		font-weight: 400;

		input {
			flex: 1;
			margin-left: 32rpx;
			text-align: right;
		}

		.item {
			width: 100%;
			height: 104rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1rpx solid rgba(195, 195, 195, 0.3);

		}
	}

	.btn {
		margin: 260rpx auto 0;
		width: 424rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		border-radius: 600rpx;
		opacity: 1;
		background: $boxBg;
		color: #FFFFFF;
	}
</style>
